<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Macaddress extends AdminController{
	public $_validation = null;
	
	function __construct(){
		parent::__construct();
		$this->load->model('MMacaddress');
		
		$this->_validation = Array(
			array('field'=>'mac', 'label'=>'mac地址', 'rules'=>'trim|required|max_length[64]')
			,array('field'=>'description', 'label'=>'详情介绍', 'rules'=>'trim|required|max_length[255]')
			,array('field'=>'status', 'label'=>'状态', 'rules'=>'integer')
			,array('field'=>'update_time', 'label'=>'更新时间', 'rules'=>'')
		);
		
	}
	
	function index($game_tag=null){
		//$this->output->enable_profiler(TRUE);
		$this->load->library('FormFilter');
		$this->load->helper('formfilter');
		$this->formfilter->addFilter('mac','where');
		$this->formfilter->addFilter('status','where');
		
		
		if($begintime = filterValue('macaddress_create_time_begin')){
		    $this->formfilter->addFilter('macaddress_create_time_begin', 'where',array('create_time >= ',strtotime($begintime.' 00:00:00')));
		}
		if($endtime = filterValue('macaddress_create_time_end')){
		    $this->formfilter->addFilter('macaddress_create_time_end', 'where',array('create_time <= ',strtotime($endtime.' 23:59:59')));
		}
		
		
		$filterCount = $this->MMacaddress->getCount();  //过滤数量
		$limit = $this->pagination($filterCount,'');
		$list = $this->MMacaddress->getList($limit);
		
		$this->assign('list', $list);
		$this->assign('filterCount', $filterCount);
		$this->assign('totalCount', $this->MMacaddress->getTotalCount());
		$this->layout();
	}
	
	
	
	function add(){
	    $obj = $this->MMacaddress->createVo();
	    $this->load->library('form_validation');
	    $this->form_validation->set_rules($this->_validation);
	    if($this->form_validation->run()==TRUE){
	        $this->load->helper('populate');
	        $newObj = populate((Object)((Array)$obj), $this->form_validation->post());
	        if($this->MMacaddress->add($newObj)){
	            successAndRedirect(l('edit_success'));
	        }else{
	            errorAndRedirect(l('data_fail'));
	        }
	    }
	    
	    $this->assign('obj', $obj);
	    $this->layout();
	}
	
	function edit($id){
	    if(!is_numeric($id)){
	        show_error(l('id_not_null'));
	    }
	    $obj = $this->MMacaddress->getOne(Array('id'=>$id));
	    if(!$obj){
	        errorAndRedirect('未找到定义！');
	    }
	    $this->editObj = $obj;
	    $this->load->library('form_validation');
	    $this->form_validation->set_rules($this->_validation);
	    if($this->form_validation->run()==TRUE){
	        $this->load->helper('populate');
	        $newObj = populate((Object)((Array)$obj), $this->form_validation->post());
	        if($this->MMacaddress->update($newObj)){
	            successAndRedirect(l('edit_success'));
	        }else{
	            errorAndRedirect(l('data_fail'));
	        }
	    }
	    $this->assign('obj', $obj);
	    $this->layout();
	}
	function delete($id, $update_time){
	    if(!is_numeric($id) || !is_numeric($update_time)){
	        show_error(l('id_not_null'));
	    }
	    if(!$this->MMacaddress->delete($id, $update_time)){
	        errorAndRedirect(l('data_fail'));
	    }
	    successAndRedirect(l('delete_success'));
	}
	
}